const str = "asdfghjklal";

function foo(str) {
  const arr = [];
  let maxLength = 0;
  for (let i = 0; i < str.length; i++) {
    if (!arr.includes(str[i])) {
      arr.push(str[i]);
    } else {
      arr.shift();
    }
    maxLength = maxLength > arr.length ? maxLength : arr.length;
  }
  return maxLength;
}
console.log(foo(str))